// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
/* eslint-disable */
import Vue from 'vue'

import App from './App'
import router from './router'
// import fastClick from 'fastclick'
import VueAwesomeSwiper from 'vue-awesome-swiper'

import store from './store/index'
import Vant from 'vant';
import 'vant/lib/index.css';

Vue.use(Vant);


Vue.config.productionTip = false
// fastClick.attach(document.body);//解决移动端 点击事件 延迟的问题

import Vconsole from 'vconsole';
let vConsole = new Vconsole();
import tools from "../src/tools/tools";
import comm from "../src/tools/comm";
router.beforeEach((to, from, next) => {
  // console.log("router to.path=" + to.path);
 // 尝试获取用户信息，如果失败则重定向到登录页面
 try {
  let tokenString = tools.getLocalData(comm.TOKEN);
  let token = tokenString!="undefined" ? JSON.parse(tokenString) : null;
  if (to.path !== '/login' && !token) {
    next('/login');
  } else {
    next();
  }
} catch (error) {
  console.error('Failed to parse user info:', error);
  next('/login'); // 如果解析失败，也重定向到登录页面
}
});

Vue.use(VueAwesomeSwiper);
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

